package bgg4j;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class GameInfo extends Game {

	public GameInfo(Element elem, Bgg bgg) throws BggException {
		super(elem, bgg);
		// TODO 自動生成されたコンストラクター・スタブ
	}

	public String getName(){
		return this.getChildText("name");
	}
	
	public String getDesigner(){
		return this.getChildText("boardgamedesigner",true);
	}
	
	public int getYear(){
		int ret;
		ret = 0;
		if (!this.getChildText("yearpublished").equals("")){
			ret = Integer.valueOf(this.getChildText("yearpublished"));
		}
		return ret;
	}
	
	public int getMinPlayer(){
		int ret;
		ret = 0;
		if (!this.getChildText("minplayers").equals("")){
			ret = Integer.valueOf(this.getChildText("minplayers"));
		}
		return ret;
	}
	
	public int getMaxPlayer(){
		int ret;
		ret = 0;
		if (!this.getChildText("maxplayers").equals("")){
			ret = Integer.valueOf(this.getChildText("maxplayers"));
		}
		return ret;
	}
	
	public int getPlayingTime(){
		int ret;
		ret = 0;
		if (!this.getChildText("playingtime").equals("")){
			ret = Integer.valueOf(this.getChildText("playingtime"));
		}
		return ret;
	}
	
	public String getDescription(){
		return this.getChildText("description");
	}
	
	/*
	public int getRank(){
		if (this.getChildText("rank") == null){
		return -1;	
		}else{
		return Integer.valueOf(this.getChildText("rank"));
		}
	}
	
	public float getBayesAverage(){
		if (this.getChildText("bayesaverage") == null){
		return 0;	
		}else{
		return Float.valueOf(this.getChildText("bayesaverage"));
		}
	}
	*/
	
	public 
    /*package*/ static GameInfo constructGameInfo(Document doc,
            Bgg bgg) throws BggException{
            if (null == doc) {
                return null;
            } else {
                try {
                    ensureRootNodeNameIs("boardgames", doc.getDocumentElement());
                    NodeList gamecontents = doc.getDocumentElement().getElementsByTagName(
                            "boardgame");
                    Element status = (Element) gamecontents.item(0);

                    return new GameInfo(status, bgg);
                } catch (BggException te) {
                    return null;
                }
            }
        }
}